package com.jiangds.open.check.checker;

import com.jiangds.open.check.Checker;
import com.jiangds.open.exception.CheckException;
import java.util.Collection;

/**
 * {@link CollectionChecker} 集合校验类
 *
 * @author jiangliang
 * @since 2021/1/5 16:38
 */
public class CollectionChecker extends AbstractChecker<Integer,Collection> {

    public CollectionChecker(Collection target) {
        super(target);
    }

    @Override
    public Checker<Integer, Collection> notEmpty() {
        notNull();
        return processor(t->t.size()>0);
    }

    @Override
    public Checker<Integer, Collection> range(Integer min, Integer max) {
        return integerRangeProcessor(Collection::size,min,max);
    }

    @Override
    public Checker<Integer, Collection> greater(Collection greaterThan) {
        return processor(t->t.size()>=greaterThan.size());
    }

    @Override
    public Checker<Integer, Collection> less(Collection lessThan) {
        return processor(t->t.size()<=lessThan.size());
    }

    @Override
    public Checker<Integer, Collection> in(Collection... args) {
        return inProcessor(Collection::equals,args);
    }

    @Override
    public Checker<Integer, Collection> regex(String regex) {
        throw new CheckException("集合不支持regex操作!");
    }
}
